<template>
	<view class="setting-wrapper wrapperLayer colRange">
		<titleBar :titleText='"个人信息更改"' :pageForm='"setting"'></titleBar>
		<view class="body-container colRange">
			<view class="userSet-content infoContainer colRange">
				<view class="keyvalueBox rowRangeAve borderBox" @click="updateAavtar()">
					<view class="leftKey">
					头像
					</view>
					<view class="rightvalue rowCenter">
						<image style="width: 46px; height: 46px; background-color: #eeeeee;border-radius: 25px;" :src="avatar"></image>
						<view class="arrow-icon defImg" style="margin-left: 10px;">
							<image src="../../../static/img/right.png" mode=""></image>
						</view>
					</view>
				</view>
				<view class="keyvalueBox rowRangeAve borderBox" @click="goUrl('/pages/my/common/updateNickName')">
					<view class="leftKey">
						昵称
					</view>
					<view class="rightvalue rowCenter">
						<text>{{nickName}}</text>
						<view class="arrow-icon defImg" style="margin-left: 10px;">
							<image src="../../../static/img/right.png" mode=""></image>
						</view>
					</view>
				</view>
				<view class="keyvalueBox rowRangeAve borderBox" @click="goUrl('/pages/my/common/changeBindMobile')">
					<view class="leftKey">
						换绑手机号
					</view>
					<view class="rightvalue rowCenter">
						<view class="arrow-icon defImg">
							<image src="../../../static/img/right.png" mode=""></image>
						</view>
					</view>
				</view>
				<view class="keyvalueBox rowRangeAve borderBox" @click="goUrl('/pages/my/common/changePwd')" >
					<view class="leftKey">
						修改密码
					</view>
					<view class="rightvalue rowCenter">
						<view class="arrow-icon defImg">
							<image src="../../../static/img/right.png" mode=""></image>
						</view>
					</view>
				</view>
				<view class="keyvalueBox rowRangeAve borderBox">
					<view class="leftKey">
					注册时间
					</view>
					<view class="rightvalue rowCenter">
						{{registerTime}}
					</view>
				</view>
			</view>

		</view>

		<u-toast ref="uToast" />
	</view>
</template>
<script>
	import titleBar from '../../../components/customize/titlebar.vue'
	export default {
		components: {
			titleBar
		},
		data() {
			return {
				avatar:'',
				nickName:'',
				mobile:'',
				registerTime:'',
			}
		},
		onShow(){
			if(this.$utils.isNotEmpty(this.$store.state.vuex_user.avatar)){
				this.avatar = this.$store.state.vuex_user.avatar;
			}
			if(this.$utils.isNotEmpty(this.$store.state.vuex_user.nickName)){
				this.nickName = this.$store.state.vuex_user.nickName;
			}
			if(this.$utils.isNotEmpty(this.$store.state.vuex_user.mobile)){
				this.mobile = this.$store.state.vuex_user.mobile;
			}
			if(this.$utils.isNotEmpty(this.$store.state.vuex_user.registerTime)){
				this.registerTime = this.$store.state.vuex_user.registerTime;
			}
		},
		onLoad() {
			
		},
		methods: {
			goUrl(url) {
				uni.navigateTo({
					url: url
				})
			},
			//更改头像
			updateAavtar(){
				debugger
				console.info(this.$store.state.vuex_config.baseUrl)
				let _this = this;
				uni.chooseImage({ // 从本地相册选择图片或使用相机拍照。
					count: 1,//默认选择1张图片
					sizeType: ['original', 'compressed'],//original 原图，compressed 压缩图，默认二者都有
					success:  (res)=> {
						console.log(res.tempFilePaths[0]);//成功则返回图片的本地文件路径列表 tempFilePaths
						uni.uploadFile({//将本地资源上传到开发者服务器
							url: this.$store.state.vuex_config.baseUrl + '/api/common/upload', //接口地址
							filePath: res.tempFilePaths[0],//图片地址
							name: 'file',
							header: {
								'Authorization': this.$store.state.vuex_token
							},
							success: (uploadFileRes) => {
								debugger
								let data = JSON.parse(uploadFileRes.data)
								if(data.code == 200){
									this.avatar = data.url;
									 this.$u.vuex('vuex_user.avatar', data.url)
								}
							}
						});
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	page {
		color: #333333;
		font-size: 30rpx;
		font-weight: 500;
		background-color: #F0F1F7;
	}
	.setting-wrapper {
		.body-container {
			width: 100%;
			margin-top: 20rpx;

			.infoContainer {
				width: 100%;
				background-color: #FFFFFF;

				.keyvalueBox {
					width: 100%;
					height: 100rpx;
					border-bottom: 1rpx solid #F2F2F2;
					padding: 0 30rpx;

					.leftKey {
						font-size: 28rpx;
						font-weight: 500;
						color: #333333;
					}

					.rightvalue {
						.rightText {
							font-size: 24rpx;
							font-weight: 400;
							color: #999999;
							margin-right: 15rpx;
						}

						.arrow-icon {
							width: 10rpx;
							height: 18rpx;
						}
					}
				}
			}

			.logOut {
				width: 100%;
				height: 100rpx;
				margin-top: 20rpx;
				background-color: #FFFFFF;

				.outText {
					font-size: 28rpx;
					font-weight: 500;
					color: #333333;
				}
			}
		}
	}
</style>
